package com.pureut.equipment.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.equipment.domain.dto.InspectionItemDto;
import com.pureut.equipment.domain.dto.InspectionItemPlanDto;
import com.pureut.equipment.domain.vo.InspectionItemPlanVo;
import com.pureut.equipment.domain.vo.InspectionItemVo;
import com.pureut.equipment.domain.vo.MaintenancePlanVo;
import com.pureut.equipment.service.InspectionItemPlanService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;

/***
 *
 * Author:点检计划控制层
 * Date:2023/04/25 10:12
 * @DESC
 */
@RestController
@RequestMapping("/inspection-item-plan")
public class InspectionItemPlanController extends BaseController {

    /**
     * 点检计划service
     */
    @Resource
    InspectionItemPlanService inspectionItemPlanService;

    /**
     * 点检计划列表
     *
     * @param inspectionItemPlanVo
     * @return
     */
    @RequiresPermissions("device:spotCheck:plan:list")
    @GetMapping("/list")
    public TableDataInfo list(InspectionItemPlanVo inspectionItemPlanVo) {
        startPage();
        List<InspectionItemPlanDto> list = inspectionItemPlanService.getList(inspectionItemPlanVo);
        return getDataTable(list);
    }

    /**
     * 新增
     */
    @RequiresPermissions("device:spotCheck:plan:add")
    @Log(title = "新增", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody InspectionItemPlanVo inspectionItemPlanVo) throws Exception {
        return toAjax(inspectionItemPlanService.add(inspectionItemPlanVo));
    }

    /**
     * 删除
     */
    @RequiresPermissions("device:spotCheck:plan:remove")
    @Log(title = "删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{id}")
    public AjaxResult add(@PathVariable("id") Long id) {
        return toAjax(inspectionItemPlanService.deleteInspectionItemPlan(id));
    }

    /**
     * 修改
     */
    @RequiresPermissions("device:spotCheck:plan:edit")
    @Log(title = "修改", businessType = BusinessType.UPDATE)
    @PutMapping("/updateItemPlan")
    public AjaxResult updateItemPlan(@RequestBody InspectionItemPlanVo inspectionItemPlanVo) {
        return toAjax(inspectionItemPlanService.updateItemPlan(inspectionItemPlanVo));
    }

    /**
     * 查看
     */
    @RequiresPermissions("device:spotCheck:plan:query")
    @GetMapping("/getView/{id}")
    public AjaxResult getView(@PathVariable("id") Long id) {
        return AjaxResult.success(inspectionItemPlanService.getItemPlanView(id));
    }

    /**
     * 启用
     */
    @RequiresPermissions("device:spotCheck:plan:enable")
    @GetMapping("/enable/{id}")
    public AjaxResult enable(@PathVariable("id") Long id) throws Exception {
        return toAjax(inspectionItemPlanService.enable(id));
    }

    /**
     * 停用
     */
    @RequiresPermissions("device:spotCheck:plan:stop")
    @GetMapping("/stop/{id}")
    public AjaxResult stop(@PathVariable("id") Long id) {
        return toAjax(inspectionItemPlanService.stop(id));
    }


    /**
     * 根据计划开始时间和结束时间定时修改计划状态(定时任务调用)
     */
    @PostMapping("/updateInspectionStatusByTime")
    public AjaxResult updateInspectionStatusByTime() throws ParseException {
        return toAjax(inspectionItemPlanService.updateInspectionStatusByTime());
    }
}
